#include "create_table_dialog.h"
#include "ui_create_table_dialog.h"
#include <QGridLayout>
#include <QPushButton>

CreateTableDialog::CreateTableDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CreateTableDialog),
    m_rows(3),
    m_cols(3)
{
    ui->setupUi(this);
    initUi();
    initEvents();
}

CreateTableDialog::~CreateTableDialog()
{
    delete ui;
}

int CreateTableDialog::rows()
{
    return m_rows;
}

int CreateTableDialog::cols()
{
    return m_cols;
}

void CreateTableDialog::initUi()
{

}

void CreateTableDialog::initEvents()
{
    connect(ui->tableSelectorWidget, &TableSelectorWidget::hoverPosition, this, [=](int row, int col){
        if (0 != row && 0 != col)
        {
            ui->tipLabel->setText(QStringLiteral("%1行*%2列表格").arg(row).arg(col));
        }
        else
        {
            ui->tipLabel->setText(QStringLiteral("插入表格"));
        }
    });

    connect(ui->tableSelectorWidget, &TableSelectorWidget::selectPosition, this, [=](int row, int col){
        m_rows = row;
        m_cols = col;
        accept();
    });
}
